package com.linkwedo.saas.email;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;

public class EmailClient {
	private static Properties properties = new Properties();
	private final static String HOST = "mail.smtp.host";
	private final static String USERNAME = "mail.smtp.auth.username";
	private final static String PASSWORD = "mail.smtp.auth.password";
	private final static String NAME = "mail.smtp.from.name";
	private final static String FROM = "mail.smtp.from";

	static {
		try {
			properties.load(EmailService.class
					.getResourceAsStream("/email.properties"));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static HtmlEmail getInstance() throws EmailException {
		HtmlEmail email = new HtmlEmail();
		email.setHostName(properties.getProperty(HOST));
		email.setAuthentication(properties.getProperty(USERNAME),
				properties.getProperty(PASSWORD));
		email.setFrom(properties.getProperty(FROM),
				properties.getProperty(NAME));
		email.setCharset("utf-8");
		return email;
	}
}
